require('./index.css');
let _util = require('util/util.js');
let template = require('./index.art');

let sideBar = {
    option: {
        name: '',
        navList: [
            {
                name: 'information-manage',
                desc: '信息管理',
                iconClass: 'fa fa-address-book',
                isActive: false,
                href: '#',
                hasChild: true,
                children: [
                    {
                        name: 'file-manage',
                        desc: '目录管理',
                        iconClass: 'fa fa-circle-o',
                        href: './index.html',
                        isActive: false,
                    },
                    {
                        name: 'file-location-manage',
                        desc: '归档位置管理',
                        iconClass: 'fa fa-circle-o',
                        href: './file-location.html',
                        isActive: false,
                    }
                ]
            },
            {
                name: 'trash',
                desc: '回收站',
                href: '#',
                iconClass: 'fa fa-trash',
                isActive: false,
                hasChild: true,
                children: [
                    // {
                    //     name: 'trash-file',
                    //     desc: '目录整理',
                    //     href: './trash.html',
                    //     iconClass: 'fa fa-circle-o',
                    //     isActive: false,
                    //     hasChild: false,
                    // },
                    {
                        name: 'trash-certificate-photos',
                        desc: '目录整理',
                        href: './trash-certificate-photos.html',
                        // href: '/catalogue/goToRecycle',
                        iconClass: 'fa fa-circle-o',
                        isActive: false,
                        hasChild: false,
                    }
                ]
            },
            {
                name: 'system-manage',
                desc: '系统管理',
                iconClass: 'fa fa-windows',
                href: '#',
                isActive: false,
                hasChild: true,
                children: [
                    {
                        childname: 'log-manage',
                        desc: '日志管理',
                        iconClass: 'fa fa-circle-o',
                        href: '#',
                        isActive: false,
                    },
                    {
                        childname: 'user-manage',
                        desc: '系统用户管理',
                        iconClass: 'fa fa-circle-o',
                        href: '#',
                        isActive: false,
                    }
                ]
            },
        ]
    },
    init: function (option) {
        $.extend(this.option, option);
        this.renderSideBar();
    },
    renderSideBar: function () {

        for (let i = 0, iLength = this.option.navList.length; i < iLength; i++) {
            const iElement = this.option.navList[i];

            if (iElement.hasChild) {

                let iElement_children = iElement.children;

                for (let j = 0, jLength = iElement_children.length; j < jLength; j++) {
                    const jElement = iElement_children[j];
                    jElement.name === this.option.name ? jElement.isActive = true : '';
                    if (jElement.isActive) {
                        iElement.isActive = true;
                    }
                }
            } else {
                iElement.name === this.option.name ? iElement.isActive = true : '';
            }
        }

        let sidebar = _util.renderHtml(template, {
            navList: this.option.navList
        });

        $('.sidebar-menu').html(sidebar);

    }
}

module.exports = sideBar;